package com.zhtools.excel.export;

public abstract class AbstractPageExport<T> implements PageExport<T> {
    /**
     * 获取总记录数
     *
     * @return
     */
    protected abstract Long getTotalRows();

    @Override
    public Long getTotalPage() {
        Long totalPage = 0L;
        Long totalRows = getTotalRows();
        if (totalRows == null || totalRows.longValue() == 0) {
            return totalPage;
        }
        Long pageSize = getPageSize();
        if (pageSize == null || pageSize.longValue() == 0) {
            return totalPage;
        }
        if (totalRows % pageSize == 0) {
            totalPage = totalRows / pageSize;
        } else {
            totalPage = (totalRows / pageSize) + 1;
        }
        return totalPage;
    }
}
